﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AspNetCs.Common;
using AspNetCs.Bll;
using AspNetCs.Model;

public partial class Master_Admin_AddMusic :Admin_BasePage
{
    protected MusicBLL bll = Music_Bll.CreateNew;
    protected string SelMusicType = "selected";
    protected string InputMusicType = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        IsExit();
        if(!IsPostBack)
        {
            GetParas();
        }
    }


    public void GetParas()
    {
        int Id = StringHelper.isNumber_int(Request["Id"]);
        if (Id == 0)
        {
            btnSubmit.Visible = true;
            Button1.Visible = false;
        }
        else
        {
            ViewState["Id"] = Id;
            MusicModel model = GetModel(Id);
            if(model.Id>0)
            {
                txtMusicName.Text = model.MusicName;
                Txt_PicName.Text = model.MusicPath;
                if(model.MusicType==1)
                {
                    SelMusicType = "";
                    InputMusicType = "selected";
                }
            }
            Button1.Visible = true;
            btnSubmit.Visible = false;
        }
    }

    public MusicModel GetModel(int Id)
    {
        DataTable dataTable = bll.GetDataTable("id="+Id);
        MusicModel model = new MusicModel();
        if(dataTable.Rows.Count>0)
        {
            model=bll.GetModel(dataTable.Rows[0]);
        }
        return model;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ViewState["Id"] != null)
        {
            int id = StringHelper.isNumber_int(ViewState["Id"].ToString());
            AspNetCs.Model.MusicModel model = new AspNetCs.Model.MusicModel();
            model.Id = id;
            model.MusicName = txtMusicName.Text;
            model.MusicPath = Txt_PicName.Text;
            model.MusicType = StringHelper.isNumber_int(Request["selType"]);
            bll.UpdateMusic(model);
        }
        ResultStr("Admin_ManageMusic.aspx", "修改成功");

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        AspNetCs.Model.MusicModel model = new AspNetCs.Model.MusicModel();
        model.MusicName = txtMusicName.Text;
        model.MusicPath = Txt_PicName.Text;
        model.MusicType = StringHelper.isNumber_int(Request["selType"]);
        model.CreateId = AdminInfo.Id;
        model.AddTime = DateTime.Now;
        bll.AddMusic(model);

        ResultStr("Admin_ManageMusic.aspx", "添加成功");
    }
}
